<?php

use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use kartik\grid\GridView;
use backend\modules\supplier\models\Storage;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\supplier\models\RackSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '货架';
$this->params['breadcrumbs'][] = $this->title;

$storageSelect = array_merge ( [''=>'不过滤'] ,  ArrayHelper::map(Storage::getAll(), 'id', 'name') );

?>
<div class="rack-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('新建', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            //'id',
            [
                'attribute' => 'name',
                'content' => function($data, $row) {
                    return $data->usedAcount > 0 ? Html::a($data->name, ['storage/slot', 'SlotSearch' => ['rack_id' => $data->id]]) : $data->name;
                },
            ],
            [
                'attribute' => 'storage_id',
                'filterType'=>GridView::FILTER_SELECT2,
                'filter'=>$storageSelect, 
                'content' => function($data, $row) {
                    return $data->storage->name;
                },
            ],
            'sort',

            [
                'class' => 'yii\grid\ActionColumn',
                'buttons'=>[
                    'delete' => function ($url, $model, $key) {
                        return $model->usedAcount ==0 ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url,['data-confirm'=>'您确定要删除此项吗？','data-method'=>'post','data-pjax'=>0]) : '';
                    },
                ],
            ],
        ],
    ]); ?>

</div>
